package com.foxnicweb.app.patent.generator.module.patent;

import com.foxnicweb.app.constants.db.PatentTables;
import com.foxnicweb.app.constants.db.PatentTables.PAT_PATENT_PROCESS;
import com.foxnicweb.app.constants.enums.patent.PatentProcessStatus;
import com.foxnicweb.app.constants.enums.patent.PatentSubType;
import com.foxnicweb.app.constants.enums.patent.ProcessRoleType;
import com.foxnicweb.app.domain.patent.*;
import com.foxnicweb.app.domain.patent.meta.PatentMeta;
import com.foxnicweb.app.domain.patent.meta.PatentProcessMeta;
import com.foxnicweb.app.domain.patent.meta.PatentProcessRoleMeta;
import com.foxnicweb.app.patent.generator.module.CodeStarter;
import com.github.foxnic.api.bpm.IntegrateMode;
import com.github.foxnic.commons.bean.BeanNameUtil;
import com.github.foxnic.generator.builder.business.option.ControllerOptions;
import com.github.foxnic.generator.builder.model.PoClassFile;
import com.github.foxnic.generator.builder.model.PojoProperty;
import com.github.foxnic.generator.builder.model.VoClassFile;
import com.github.foxnic.generator.builder.view.option.*;
import com.github.foxnic.generator.config.WriteMode;
import com.github.foxnic.sql.entity.naming.DefaultNameConvertor;
import org.github.foxnic.web.domain.bpm.meta.DemoLeaveMeta;
import org.github.foxnic.web.domain.bpm.meta.ProcessInstanceMeta;
import org.github.foxnic.web.domain.bpm.meta.TaskMeta;
import org.github.foxnic.web.domain.hrm.meta.EmployeeMeta;

import java.util.List;

public class PatentProcessConfig extends CodeStarter.BaseCodeConfig<PAT_PATENT_PROCESS> {

    public PatentProcessConfig() {
        super(PREFIX_PATENT, PAT_PATENT_PROCESS.$TABLE,"pat_", 4);
    }

    @Override
    public void configModel(PoClassFile poType, VoClassFile voType) {

        poType.shadow(PAT_PATENT_PROCESS.STATUS, PatentProcessStatus.class);
        poType.addListProperty(PatentFile.class,"fileList","附件清单","附件清单");
        poType.addListProperty(PatentMember.class,"memberList","成员清单","成员附件清单");


        BeanNameUtil convertor=BeanNameUtil.instance();
        for (ProcessRoleType roleType : ProcessRoleType.values()) {
            poType.addListProperty(PatentProcessRole.class,convertor.getPropertyName(roleType.code())+"List",roleType.text()+"清单",roleType.text()+"清单");
            poType.addListProperty(String.class,convertor.getPropertyName(roleType.code())+"Ids",roleType.text()+"ID清单",roleType.text()+"ID清单");
        }


        PojoProperty p= null;
        p=poType.addMapProperty(String.class, List.class,"fileMap","附件清单","附件按节点分组");
        p.setValueGenericTypes(PatentFile.class);

        p=poType.addMapProperty(String.class, List.class,"memberMap","成员清单","成员按类型分组清单");
        p.setValueGenericTypes(PatentMember.class);

        poType.addSimpleProperty(Patent.class,"patent","专利案","专利案");
    }

    @Override
    public void configBPM(BpmOptions bpm) {
        bpm.form("patent_process");
        bpm.integrate(IntegrateMode.FRONT);
    }

    @Override
    public void configSearch(ViewOptions view, SearchAreaOptions search) {

        search.inputLayout(
                new Object[] {PatentTables.PAT_PATENT.SUBTYPE,PAT_PATENT_PROCESS.CUSTOMER_NAME,"caseAgentIds","businessAssistantIds"},
                new Object[] {PatentTables.PAT_PATENT.TITLE,PatentTables.PAT_PATENT.SERIAL,PAT_PATENT_PROCESS.STATUS}
        );
        search.labelWidth(3,90);
    }

    @Override
    public void configList(ViewOptions view, ListOptions list) {
        // list.operationColumn().addActionButton("立即取数","fetchApiDoc");
        list.columnLayout(new Object[] {
                PatentTables.PAT_PATENT.TITLE,
                PatentTables.PAT_PATENT.SERIAL,
                PAT_PATENT_PROCESS.CUSTOMER_NAME,
                PAT_PATENT_PROCESS.STATUS,
                "processStatus",
                "currNodes",
                "currNodesTime",
                PatentTables.PAT_PATENT.SUBTYPE,
                PAT_PATENT_PROCESS.IS_GOT_BASE,
                PAT_PATENT_PROCESS.CAN_OFFICE_DONE,
                PAT_PATENT_PROCESS.IS_MATERIAL_COMPLETE,
                PAT_PATENT_PROCESS.CAN_AGENT_DONE,
                PAT_PATENT_PROCESS.FINALIZED,
                PAT_PATENT_PROCESS.CREATE_TIME
        });
        list.disableCreateNew();

    }

    @Override
    public void configForm(ViewOptions view, FormOptions form, FormWindowOptions formWindow) {

        formWindow.bottomSpace(16);
        form.labelWidth(100);
        //form.disableFooter().disableMargin();


    }

    @Override
    public void configFields(ViewOptions view) {
        view.field(PAT_PATENT_PROCESS.ID).basic().hidden();



        view.field(PAT_PATENT_PROCESS.PROCESS_INSTANCE_ID).basic().hidden();

        view.field(PAT_PATENT_PROCESS.IS_GOT_BASE)
                .form().logicField().on("已交",1).off("未交",0).defaultValue(false);

        view.field(PAT_PATENT_PROCESS.NO_BASE_CONTINUE)
                .form().logicField().on("继续",1).off("终止",0).defaultValue(false)
                .table().disable();

        view.field(PAT_PATENT_PROCESS.CAN_OFFICE_DONE)
                .form().logicField().on("可以",1).off("不能",0).defaultValue(false);

        view.field(PAT_PATENT_PROCESS.NO_BASE_CONTINUE)
                .form().logicField().on("继续",1).off("终止",0).defaultValue(false);

        view.field(PAT_PATENT_PROCESS.IS_MATERIAL_COMPLETE)
                .form().logicField().on("完整",1).off("缺失",0).defaultValue(false);


        view.field(PAT_PATENT_PROCESS.RETRIEVAL).basic().label("下一步骤")
                .table().disable()
                .form().logicField().on("检索",1).off("撰稿",0).defaultValue(false);


        view.field(PAT_PATENT_PROCESS.CAN_AGENT_DONE)
                .form().logicField().on("可以",1).off("不能",0).defaultValue(false);

        view.field(PAT_PATENT_PROCESS.FINALIZED)
                .form().logicField().on("定稿",1).off("待定",0).defaultValue(false);


        view.field(PatentTables.PAT_PATENT.TITLE).basic().label("名称")
                .search().on(PatentTables.PAT_PATENT.TITLE).fuzzySearch().form().hidden()
                .table().fillByProperty(PatentProcessMeta.PATENT, PatentMeta.TITLE);


        view.field(PatentTables.PAT_PATENT_PROCESS.SUBTYPE)
                .search().label("类型").triggerOnSelect(true)
                .form().radioBox().enumType(PatentSubType.class);

        view.field(PAT_PATENT_PROCESS.CUSTOMER_NAME)
                .search().label("客户").inputWidth(120)
                .form().hidden();

        view.field(PatentTables.PAT_PATENT.SERIAL).basic().label("编号")
                .form().hidden()
                .table().fillByProperty(PatentProcessMeta.PATENT,PatentMeta.SERIAL)
                .search().on(PatentTables.PAT_PATENT.SERIAL).fuzzySearch().inputWidth(120);



        view.field(PAT_PATENT_PROCESS.STATUS).basic().label("专利状态")
                .search().label("专利状态").triggerOnSelect(true)
                .form().selectBox().enumType(PatentProcessStatus.class).form().hidden()
                .table().useThemeBadgeStyle();


        view.field("processStatus").basic().label("审批状态")
                //.search().label("状态").triggerOnSelect(true)
                .form().hidden()
                .table().fillByProperty(PatentProcessMeta.DEFAULT_PROCESS,ProcessInstanceMeta.APPROVAL_STATUS_NAME).useThemeBadgeStyle();


        view.field("currNodes").basic().label("待审节点")
                .search().hidden().form().hidden()
                .table().fillByProperty(PatentProcessMeta.DEFAULT_PROCESS, ProcessInstanceMeta.TODO_TASKS, TaskMeta.NODE_NAME);

        view.field("currNodesTime").basic().label("节点始于")
                .search().hidden().form().hidden()
                .table().fillByProperty(PatentProcessMeta.DEFAULT_PROCESS, ProcessInstanceMeta.TODO_TASKS, TaskMeta.CREATE_TIME);


        BeanNameUtil convertor=BeanNameUtil.instance();
        for (ProcessRoleType roleType : ProcessRoleType.values()) {
            view.field(convertor.getPropertyName(roleType.code())+"Ids").basic().label(roleType.text())
                    .search().on(PatentTables.PAT_PATENT_PROCESS_ROLE.EMPLOYEE_ID)
                    .table().fillByProperty(convertor.getPropertyName(roleType.code())+"List", PatentProcessRoleMeta.EMPLOYEE, EmployeeMeta.NAME)
                    .form().button().chooseEmployee(false).width("200px",true);
        }



    }

    @Override
    public void configController(ControllerOptions controller) {

//        // 定义一个控制器方法
//        controller.restApi("立即取数","fetchApiDoc","fetch-api-doc", RequestMethod.POST,"获取API文档")
//                .addSimpleParameter(String.class,"id","来源ID",true,"001","来源ID");
//
//        // 定义一个控制器方法
//        controller.restApi("获得API接口节点","queryApiNodes","query-api-nodes", RequestMethod.POST,"获得API接口节点")
//                .addSimpleParameter(String.class,"id","id",true,"example","id")
//                .listResult(ZTreeNode.class,"节点树形结构");
//
//        // 定义一个控制器方法
//        controller.restApi("获得API接口详情","queryApiDetail","query-api-detail", RequestMethod.POST,"获得API接口详情")
//                .addSimpleParameter(String.class,"path","path",true,"/example/query-list","path")
//                .addSimpleParameter(String.class,"method","method",true,"post","method");

    }



    @Override
    public void configOverrides() {
        this.context.overrides()
            .setServiceIntfAnfImpl(WriteMode.COVER_EXISTS_FILE) //服务与接口
            .setControllerAndAgent(WriteMode.COVER_EXISTS_FILE) //Rest
            .setPageController(WriteMode.COVER_EXISTS_FILE) //页面控制器
            .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
            .setListPage(WriteMode.COVER_EXISTS_FILE) //列表HTML页
            .setExtendJsFile(WriteMode.COVER_EXISTS_FILE); //扩展页面
    }

    public static void main(String[] args) {
        execute();
    }

}
